/**
 * Author : Fengyuan(Franklin) Zhang
 * Date : 2018/12/28
 * Description : Data model
 */

var BaseModel = require('./baseModel');
var ObjectId = require('mongodb').ObjectID;
var mongoose = require('./mongooseModel');

function DataModel(data) {
    if(data){
        if(!data._id){
            this._id = new ObjectId();
        }
        else{
            this._id = data._id;
        }
        if(!data.d_datetime){
            this.d_datetime = (new Date()).toISOString();
        }
        else{
            this.d_datetime = data.d_datetime;
        }
        if(!data.d_size){
            this.d_size = 0;
        }
        else{
            this.d_size = data.d_size;
        }
        if(!data.d_md5){
            this.d_md5 = '';
        }
        else{
            this.d_md5 = data.d_md5;
        }
        if(!data.d_pwd){
            this.d_pwd = '';
        }
        else{
            this.d_pwd = data.d_pwd;
        }
        if(!data.d_requested){
            this.d_requested = false;
        }
        else{
            this.d_requested = data.d_requested;
        }
        if(!data.d_tag){
            this.d_tag = '';
        }
        else{
            this.d_tag = data.d_tag;
        }
        if(!data.d_fullpath){
            this.d_fullpath = '';
        }
        else{
            this.d_fullpath = data.d_fullpath;
        }
    }
    else{
        this._id = new ObjectId();
        this.d_datetime = (new Date()).toISOString();
        this.d_size = 0;
        this.d_md5 = '';
        this.d_pwd = '';
        this.d_requested = false;
        this.d_tag = '';
        this.d_fullpath = '';
    }
    return this;
}

DataModel.__proto__ = BaseModel;
module.exports = DataModel;

var dataSchema = new mongoose.Schema({
    d_datetime : String,
    d_size : Number,
    d_md5 : String,
    d_pwd : String,
    d_requested : Boolean,
    d_tag : String,
    d_fullpath : String
},{collection:'data'});
var DataScm = mongoose.model('data', dataSchema);
DataModel.baseModel = DataScm;
DataModel.modelName = "Data";